//引用Vuex
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
//实例store对象
const store = new Vuex.Store({
	state: {
		token: "",
		user: {},
		serverUrl: 'https://spl.cc163.tech/prod-api', //请求地址  生产
		tabbarHeight: '', // tabbar高度
		orderList: [],
		orderListParams: {
			pageNum: 1,
			pageSize: 10,
			pageTotal: 1,
			status: 'loadmore',
		}
		//serverUrl: 'http://192.168.0.107:8009', //请求地址  本地
	},
	getters: {
		getToken: (state) => {
			if(state.token) {
				return state.token
			}
			return uni.getStorageSync('token')
			
		},
		getUser: (state) => {
			if(JSON.stringify(state.user) == '{}') {
				return uni.getStorageSync('user')
			}
			return state.user
		},
		getTabbarHeight: state => uni.getSystemInfoSync().windowBottom,
		orderList: (state) =>  state.orderList,
		orderListParams: (state) => state.orderListParams
	},
	mutations: {
		setToken(state, token) {
			state.token = token;
		},
		setUser(state, user) {
			state.user = user;
		},
		setOrderList(state, list) {
			if(state.orderListParams.pageNum === 1) {
				state.orderList = list;
			} else {
				state.orderList = state.orderList.concat(list)
			}
		},
		setOrderListParams(state, data) {
			state.orderListStatus = Object.assign(state.orderListParams, data);
			console.log(state.orderListParams)
		}
	}
})

//导出store对象
export default store
